package com.openarena.model.dao;

import com.openarena.model.FlagActionEnum;
import com.openarena.model.Game;
import com.openarena.model.GameFlagEvent;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

public class GameFlagEventDAO extends InfArenaDAO {

    private static final Logger logger = Logger.getLogger(GameFlagEventDAO.class.getCanonicalName());

    public GameFlagEventDAO() {
        super();
    }

    public List<GameFlagEvent> getGameFlagCaptures(Game game) {
        Session session = null;
        try {
            session = getSession();
            List<GameFlagEvent> events = session
                    .createCriteria(GameFlagEvent.class)
                    .add(Restrictions.eq("gameId", game.getId()))
                    .add(Restrictions.eq("actionName", FlagActionEnum.CAPTURED_FLAG.toString()))
                    .addOrder(Order.asc("gameTime"))
                    .list();
            return events;
        } catch (Exception e) {
            logger.log(Level.SEVERE, null, e);
            return Collections.EMPTY_LIST;
        } finally {
            close(session);
        }
    }
}
